%将通过filterDesigner生成的SOS、G矩阵处理，保存到本地的iir_coeffs.h头文件
filter_index=8;
currentDateTime = datetime('now', 'Format', 'yyyy-MM-dd HH:mm:ss');
userName = getenv('USERNAME');
SOS_num=size(SOS,1);
G_num=size(G,1);
filepath=sprintf('../app/IIR/iir_coeffs%d.h',filter_index);
fileID = fopen(filepath,'w');
fprintf(fileID, '// headfile creat time：%s\n', currentDateTime);
fprintf(fileID, '// developer name：%s\n', userName);
fprintf(fileID,"#ifndef __IIR_COEFFS%d_H_\n",filter_index);
fprintf(fileID,"#define __IIR_COEFFS%d_H_\n\n\n",filter_index);

fprintf(fileID,"#define SOS%d_NUM (%dU)\n\n",filter_index,SOS_num);

fprintf(fileID,"const float iir%d_coeffs_B[SOS%d_NUM*3] = {\n",filter_index,filter_index);

for i=1:1:SOS_num
    fprintf(fileID,'    %f, %f, %f,\n',SOS(i,1),SOS(i,2),SOS(i,3));
end

fprintf(fileID,"};\n\n");

fprintf(fileID,"const float iir%d_coeffs_A[SOS%d_NUM*3] = {\n",filter_index,filter_index);

for i=1:1:SOS_num
    fprintf(fileID,'    %f, %f, %f,\n',SOS(i,4),-SOS(i,5),-SOS(i,6));
end

fprintf(fileID,"};\n\n");

fprintf(fileID,"const float iir%d_scaleFactors[SOS%d_NUM] = {\n   ",filter_index,filter_index);

TEMP=G(1:G_num-1,1);
count=0;
for i=1:1:(G_num-1)
    fprintf(fileID,' %f,',TEMP(i,1));
    count=count+1;
    if count==3
        fprintf(fileID,'\n   ');
        count=0;
    end
end

fprintf(fileID,"\n};\n\n");

fprintf(fileID,"float iir%d_delayLine[SOS%d_NUM * 4U];\n\n",filter_index,filter_index);

fprintf(fileID,"float iir%d_in, iir%d_out;\n\n",filter_index,filter_index);

fprintf(fileID,"#endif\n");

fclose(fileID);

edit (filepath);